﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Campus {
    class Robot : Unit {
        static public List<Texture2D> idleAnim = new List<Texture2D>();
        static public List<Texture2D> walkRightAnim = new List<Texture2D>();
        static public List<Texture2D> walkLeftAnim = new List<Texture2D>();
        static public List<Texture2D> walkUpAnim = new List<Texture2D>();
        static public List<Texture2D> walkDownAnim = new List<Texture2D>();
        static public List<Texture2D> attackRightAnim = new List<Texture2D>();
        static public List<Texture2D> attackLeftAnim = new List<Texture2D>();
        static public List<Texture2D> dieAnim = new List<Texture2D>();

        private void CreateAbilites() {
            Abilities.Add("Move", new MoveAbility(this, Vector2.Zero));
            Abilities.Add("Attack", new MeleeAttack(this, null, Ability.TargetTypes.BaseEntityTarget, 10, 15, 1500));
            this.CanAttack = true;
        }

        public Robot(Vector2 position, Player player, Level level)
            : base(CreateDictionary(), position, 50, player, level, 
            new Dictionary<String, Ability>(), new Dictionary<String, AbilitySubMenu>())
        {
            m_name = "Robot";
            m_entitySelectedImage = idleAnim[0];
            Size = new Vector2(70, 70);
            CreateAbilites();
        }

        public override void Update(GameTime gameTime, bool checkInput, bool updateBoundingBox)
        {            
            base.Update(gameTime, checkInput, updateBoundingBox);
        }

        private double FindDistance(BaseEntity target)
        {
            double x = (Position.X + Size.X / 2) - (target.Position.X + target.Size.X / 2);
            double y = (Position.Y + Size.Y / 2) - (target.Position.Y + target.Size.Y / 2);

            return Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
        }

        static private Dictionary<Unit.UnitState, Animation> CreateDictionary()
        {
            Dictionary<Unit.UnitState, Animation> dict = new Dictionary<UnitState, Animation>();

            // Creates an animation based on the certain static list, then adds it to the
            // Dictionary under the appropriate state.
            dict.Add(UnitState.Idle, new Animation(idleAnim, 200, true));
            
            dict.Add(UnitState.WalkRight, new Animation(walkRightAnim, 50, true));
            dict.Add(UnitState.WalkLeft, new Animation(walkLeftAnim, 50, true));
            //dict.Add(UnitState.walkDown, new Animation(walkDownAnim, 150, true));
            dict.Add(UnitState.WalkUp, new Animation(walkUpAnim, 50, true));
            dict.Add(UnitState.AttackRight, new Animation(attackRightAnim, 150, false));
            dict.Add(UnitState.AttackLeft, new Animation(attackLeftAnim, 150, false));
            dict.Add(UnitState.Die, new Animation(dieAnim, 100, false));            

            return dict;
        }


        static public void InitializeAnimations(ContentManager Content)
        {
            // Loads all the idle animation frames
            idleAnim.Add(Content.Load<Texture2D>("Units/Robot/robotIDLE_0"));
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(Content.Load<Texture2D>("Units/Robot/robotIDLE_1"));
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[0]);
            idleAnim.Add(idleAnim[8]);

            walkRightAnim.Add(Content.Load<Texture2D>("Units/Robot/robotWALKRIGHT_0"));
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(Content.Load<Texture2D>("Units/Robot/robotWALKRIGHT_1"));
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[0]);
            walkRightAnim.Add(walkRightAnim[8]);

            walkLeftAnim.Add(Content.Load<Texture2D>("Units/Robot/robotWALKLEFT_0"));
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(Content.Load<Texture2D>("Units/Robot/robotWALKLEFT_1"));
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[0]);
            walkLeftAnim.Add(walkLeftAnim[8]);

            walkUpAnim.Add(Content.Load<Texture2D>("Units/Robot/robotWALKUP_0"));
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(Content.Load<Texture2D>("Units/Robot/robotWALKUP_1"));
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[0]);
            walkUpAnim.Add(walkUpAnim[8]);

            attackRightAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKRIGHT_0"));
            attackRightAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKRIGHT_1"));
            attackRightAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKRIGHT_2"));
            attackRightAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKRIGHT_3"));

            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKLEFT_0"));
            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKLEFT_1"));
            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKLEFT_2"));
            attackLeftAnim.Add(Content.Load<Texture2D>("Units/Robot/robotATTACKLEFT_3"));

            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_0"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_1"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_2"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_3"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_4"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_5"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_6"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_7"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_8"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_9"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_10"));
            dieAnim.Add(Content.Load<Texture2D>("Units/Robot/robotDEATH_11"));
        }
    }
}
